$('.sub').click(function(e){
   e.preventDefault();
   layui.use('layer', function () {
       var layer = layui.layer;
        //接收表单数据
        let admin_name = $('input[name=admin_name]').val().trim();
        let admin_password = $('input[name=admin_password]').val().trim();
        if (admin_name == '') {
            return layer.msg('用户名不能为空',{icon:5})
        }
        if (admin_password == '') {
            return layer.msg('密码不能为空', {
                icon: 5
            })
        }
        //发送ajax请求
        $.ajax({
            type: "post",
            url: "/admin/login",
            data: $('#myform').serialize(),
            success: function (res) {
                 if(res.status==200){
                    layer.msg('登录成功', {
                        icon: 6
                    },function(){
                        location.href='/admin/index'
                    })
                 }else{
                      return layer.msg(res.msg, {
                          icon: 5,
                          time:3000
                      })
                 }
            }
        });
       
   });

  
});

